<?php
// +----------------------------------------------------------------------
// | 项目公共调用
// +----------------------------------------------------------------------
// | Copyright (c) 2015
// +----------------------------------------------------------------------
// | Author: baiping 125618036@qq.com http://www.webipcode.com
// +----------------------------------------------------------------------
// | 2015-6-24下午6:01:45
// +----------------------------------------------------------------------
defined('BASEPATH') OR exit('No direct script access allowed');

class Publicci extends CI_Controller {
	
	/**
	 * 获取验证码
	 */
	public function getCode(){
		//第一步先清空验证码存储的session,此处是为了用户在重复刷新验证码的时候，要清除上一次的session数据
		$session_code = $this->session->userdata('code_verify');
		if ( !isset( $session_code ) ){
			$this->session->unset_userdata('code_verify');
		}
		$img_width = intval( $this->input->get('img_width') );
		$img_width = empty( $img_width ) ? 310 : $img_width;
		$this->load->helper('captcha');//加载验证码类
		$vals = array(
				'img_path' => './captcha/',
				'img_url' => base_url().'captcha/',
				'img_width' => $img_width,
				'img_height' => 50,
				'font_size'=> 40,
				'font_path'=>'./public/font/arial.ttf',
				'word_length'=>6,
				'expiration' => 60*10,//10分钟清除生成的验证码图片
				'colors'    => array(
			        'background' => array(255, 255, 255),
			        'border' => array(200, 200, 200),
			        'text' => array(17, 104, 221),
			        'grid' => array(143, 115, 186)
			    )
		);
		$cap = create_captcha($vals);
		//获取验证码字符串然后存在session中
		$code_verify = strtolower($cap['word']);
		$this->session->set_userdata('code_verify', $code_verify);
		echo $cap['image'];
	}
}